package bean;



import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;

public class UserGudang {

    private String username;
    private String namaUser;
    private String noTelepon;
    private String jenisUser;
    private String password;
    String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    String userid = "mhs115314034";
    String pass = "mhs115314034";
//    String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
//        String userid = "hr"; // gantikan dengan username anda
//        String pass = "hr"; // gantikan dengan password anda

    public UserGudang() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNamaUser() {
        return namaUser;
    }

    public void setNamaUser(String namaUser) {
        this.namaUser = namaUser;
    }

    public String getNoTelepon() {
        return noTelepon;
    }

    public void setNoTelepon(String noTelepon) {
        this.noTelepon = noTelepon;
    }

    public String getJenisUser() {
        return jenisUser;
    }

    public void setJenisUser(String jenisUser) {
        this.jenisUser = jenisUser;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean PerbandinganUser() {
        try {
            Connection connection = null;
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            ds.setPassword(password);
            ds.setUser(userid);
            connection = (Connection) ds.getConnection();
            Statement statement = connection.createStatement();
            String hasil = null;
            ResultSet resultSet = statement.executeQuery("select username, password from usergudangt "
                    + "where username = '"
                    + getUsername() + "' and password = "
                    + "'" + getPassword() + "'");
            while (resultSet.next() == true) {
                return true;
            }
            return false;
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
            return false;
        }
    }

    public String PilihJenisUser() {
        try {
            Connection connection = null;
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            ds.setPassword(password);
            ds.setUser(userid);
            connection = (Connection) ds.getConnection();
            Statement statement = connection.createStatement();
            String hasil = null;
            ResultSet resultSet = statement.executeQuery("select jenisuser from usergudangt where username = '" + getUsername() + "'");
            while (resultSet.next() == true) {
                return resultSet.getString("jenisuser");
            }
            return "0";
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
            return "0";
        }
    }
}
